package net.chowda.appinject;

import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.mortbay.jetty.handler.DefaultHandler;
import org.mortbay.jetty.handler.HandlerCollection;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;

/**
 * appinject is an application that provides an easy way to inject applications in webpages.
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Server server = new Server();
        Connector connector = new SelectChannelConnector();
        connector.setHost("127.0.0.1");
        connector.setPort(8080);
        server.setConnectors(new Connector[]{connector});

        WebAppContext wac1 = new WebAppContext();
        wac1.setContextPath("/castcluster");
        wac1.setExtractWAR(true);
        wac1.setWar("build/castcluster.war");

        WebAppContext wac2 = new WebAppContext();
        wac2.setContextPath("/ai");
        wac2.setWar("build/war");

        ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(new Handler[]{wac1, wac2});

        HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers(new Handler[]{contexts, new DefaultHandler()});
        server.setHandler(handlers);
        server.start();
        server.join();
    }
}
